package exam.tencentyun;


class ListNode{

    int val;
    ListNode next;

    public ListNode(){}
    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}

public class Main {

    public static void main(String[] args) {

    }

    private boolean myans(ListNode head){
        if(head == null){
            return false;
        }

//        Set<ListNode> set = new HashSet<>();
//
//        ListNode cur = head;
//
//        while (cur != null){
//            if(set.contains(cur)){
//                return true;
//            }
//            set.add(cur);
//            cur = cur.next;
//        }
//        return false;

        ListNode fast = head;
        ListNode slow = head;

        while (fast != null && fast.next != null){
            fast = fast.next.next;
            slow = slow.next;

            if(fast == slow){
                return true;
            }
        }
        return false;
    }

}
